package com.qtjf.qtmoneyservice.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.qtjf.qtmoneyservice.R;
import com.qtjf.qtmoneyservice.activity.ConfirmJieKuanActivity;
import com.qtjf.qtmoneyservice.constantSet.Constant;
import com.qtjf.qtmoneyservice.domain.Product;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by Administrator on 2016/12/6 0006.
 */

public class HomeRecyclerAdapter extends RecyclerView.Adapter<HomeRecyclerAdapter.SimpleViewHolder> {

    private List<Product> lists;
    private Context mContext;
    private LayoutInflater layoutInflater;

    Gson gson;

    public HomeRecyclerAdapter(List<Product> lists, Context mContext) {
        this.lists = lists;
        this.mContext = mContext;
        layoutInflater = LayoutInflater.from(mContext);
        gson=new Gson();
    }

    @Override
    public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.home_recycler_item, parent, false);
        return new SimpleViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final SimpleViewHolder holder, final int position) {
     //绑定数据
      /*  Glide.with(mContext)
                .load(Constant.HOMEADDRESS+"download/"+lists.get(position).getTouxiang())
                .bitmapTransform(new RoundedCornersTransformation(mContext, 10, 0, RoundedCornersTransformation.CornerType.ALL))
                .error(R.mipmap.error_bg)
                .placeholder(R.mipmap.error_bg)
                .crossFade(1000).into(holder.img);*/
        holder.cishuText.setText("成功借款"+lists.get(position).getSucceeNum()+"次");
        holder.jineText.setText(lists.get(position).getAmount());
        holder.qixianText.setText("借款"+lists.get(position).getDaynum()+"天");
        //holder.leiXingText.setText();

        holder.jieKuanBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, ConfirmJieKuanActivity.class);
                intent.putExtra("id",lists.get(position).getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return lists.size();
    }

    protected final static class SimpleViewHolder extends RecyclerView.ViewHolder {

        TextView jieKuanBt;
        TextView cishuText;
        TextView jineText;
        TextView qixianText;
        TextView leiXingText;

        //初始化控件
        public SimpleViewHolder(View itemView) {
            super(itemView);
            jieKuanBt= (TextView) itemView.findViewById(R.id.jiakuan_bt);
            cishuText= (TextView) itemView.findViewById(R.id.cishu_text);
            jineText= (TextView) itemView.findViewById(R.id.jine_text);
            qixianText= (TextView) itemView.findViewById(R.id.qixian_text);
            leiXingText= (TextView) itemView.findViewById(R.id.leixing_text);
        }
    }
}
